﻿using B.S.BaseData.Api.Write.Applicantion.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.GoodsCommandHandler
{
    public class GoodsHealDeleteCommandHandler : IRequestHandler<GoodsHealDeleteCommand, APIResult<int>>
    {
        private readonly IBaseRepository<GoodshealthInfo> _goodsHealInfoRepository;
        public GoodsHealDeleteCommandHandler(IBaseRepository<GoodshealthInfo> goodsHealInfoRepository)
        {
            _goodsHealInfoRepository = goodsHealInfoRepository;
        }
        public async Task<APIResult<int>> Handle(GoodsHealDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            try
            {
                var list = await _goodsHealInfoRepository.GetValues(x => x.Id == request.Id);
                list.IsDeleted= true;
                await _goodsHealInfoRepository.UpdateAsync(list);
                result.Code = ApiEnum.Success;
                result.Msg = "保健信息删除成功";
                result.Data = 1;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Code = ApiEnum.Fail;
                result.Msg = "保健信息删除失败";
                return await Task.FromResult(result);
            }
        }
    }
}
